//
//  SEGOpenDoorStrategyViewController.m
//  YYKitDemo
//
//  Created by 刘山 on 2017/11/8.
//  Copyright © 2017年 Sam. All rights reserved.
//

#import "SEGOpenDoorStrategyViewController.h"
#import "SEGTextCell.h"

@interface SEGOpenDoorStrategyViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *layouts;
@end

@implementation SEGOpenDoorStrategyViewController
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    if (self.isHideBar) {
        self.navigationController.navigationBarHidden=NO;
    }
}
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    if (self.isHideBar) {
        self.navigationController.navigationBarHidden=YES;
    }
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"开门攻略";
    self.view.backgroundColor = kColor_bg;
    [self showCustomNavigationBackButton];
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    NSArray* arr = [self data];

    _layouts = [NSMutableArray array];
    for (NSArray *object in arr) {
        NSMutableArray *arrM = [NSMutableArray array];
        for (NSDictionary *object1 in object) {
            [arrM addObject: [[SEGDoorTextLayout alloc]initWithContent:[object1 valueForKey:@"name"] ShowType:[[object1 valueForKey:@"type"] integerValue]]];
        }
        [_layouts addObject:arrM];
    }
    [self.view addSubview:self.tableView];
    [_tableView reloadData];
    //self.tableView.frame = self.view.frame;
}

#pragma mark - UITableViewDataSource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return _layouts.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSArray *data = _layouts[section];
    return data.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *cellID = @"cell";
    SEGTextCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (!cell) {
        cell = [[SEGTextCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    NSArray *data = _layouts[indexPath.section];
    [cell setLayout:data[indexPath.row]];
    cell.delegate = self;
    return cell;
}

-(void)seg_doorFix{
    /*
     instCode = "SERVICE_PAGE_WYFW";
     nodeTempInstId = "";
     serviceName = "\U7269\U4e1a\U670d\U52a1";
     action = "cn.segi.uhome.action.APPOINTMENT";
     tempInstId = 100;
     type = 0;
     */
    
    NSDictionary* dict = @{
                           @"type" : @"0",
                           @"action" : @"cn.segi.uhome.action.APPOINTMENT"
                           };
    [[SEGUhomeMediator sharedInstance]seg_pushToViewControllerWithAction:dict];
}

#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSArray *data = _layouts[indexPath.section];
    return ((SEGDoorTextLayout *)data[indexPath.row]).height;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (section == _layouts.count - 1) {
        return 0;
    }
    return 10;
}

- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath {
    return NO;
}
-(UITableView *)tableView{
    if (!_tableView) {
        _tableView = [UITableView new];
        _tableView.frame = CGRectMake(0, 0, LYScreenWidth(), LYScreenHeight() - kNavigationBarAndStatusBarHeight);
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.scrollIndicatorInsets = _tableView.contentInset;
        _tableView.backgroundColor = [UIColor clearColor];
        _tableView.backgroundView.backgroundColor = [UIColor clearColor];
    }
    return  _tableView;
}

-(NSArray*)data{
    return @[
  @[
  @{@"name" : @"开门太慢",@"type" : @"0"},
      @{@"name" : @"蓝牙门禁：\n提前配对完毕，保持蓝牙打开",@"type" : @"1"},
      @{@"name" : @"网络门禁：\n保持网络畅通",@"type" : @"1"}],
             
    @[@{@"name" : @"开门总是失败？",@"type" : @"0"},
      @{@"name" : @"蓝牙门禁：\n1、可能是距离太远，尝试靠近点\n2、重新安装程序，确保应用的蓝牙使用权限是允许的\n3、尝试使用其他系统相同的手机试一下。如：安卓系统，是否所有的安卓手机都无法打开门禁\n4、如果所有的手机都打不开门禁，可能是门禁出了问题，建议您直接联系管理处",@"type" : @"1"},
      @{@"name" : @"网络门禁：\n网络门禁的开门速度与网络的畅通有很大的关系哦，网路越好，开门越快，开门时保持良好的网络就可以了哦",@"type" : @"2"}
      ]
  ];
}
@end
